<?php
define('IN_PHPBB', true);
// Specify the path to you phpBB3 installation directory.
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// The common.php file is required.
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin(false);
$auth->acl($user->data);

$user->setup();

if (isset($config['molten_chat_installed']) and !empty($config['molten_chat_enable']))
{
	if (isset ($_GET ['action']) and isset ($_GET ['level']) and isset ($_GET ['line']))
	{
		$color = false;
		$length = strlen ($user->data['user_colour']);

		if ($length == 6)
		{
			$color = array(
				'red' => hexdec($user->data['user_colour'][0].$user->data['user_colour'][1]),
				'green' => hexdec($user->data['user_colour'][2].$user->data['user_colour'][3]),
				'blue' => hexdec($user->data['user_colour'][4].$user->data['user_colour'][5])
			);
		}
		elseif ($length == 3)
		{
			$color = array(
				'red' => hexdec($user->data['user_colour'][0].$user->data['user_colour'][0]),
				'green' => hexdec($user->data['user_colour'][1].$user->data['user_colour'][1]),
				'blue' => hexdec($user->data['user_colour'][2].$user->data['user_colour'][2])
			);
		}

		// Only registered users are handled server-side.
		if ($user->data['is_registered'])
		{
			// Join the user to the room.
			molten_chat_server::join($user->data['username'], false, $color);

			// Update user's time.
			molten_chat_server::update($user->data['username'], false, $color);
		}

		// Delay execution until new information is available.
		molten_chat_server::push((integer) $_GET['level'], (integer) $_GET['line'], (integer) $_GET['action']);

		// Get new information (if there is any).
		molten_chat_server::retrieve((integer) $_GET['level'], (integer) $_GET['line'], (integer) $_GET['action']);
	}
	else
	{
		sleep(30);
	}
}
else
{
	sleep(30);
}
?>